package com.spirit.mypopup;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.spirit.mypopup.menu.CityBean;
import com.spirit.mypopup.menu.LikeBean;
import com.spirit.mypopup.menu.MenuType;
import com.spirit.mypopup.menu.FilterMenuBar;
import com.spirit.mypopup.menu.OptionValueObject;
import com.spirit.mypopup.menu.OptionObject;
import com.spirit.mypopup.menu.OptionTitleInterface;
import com.spirit.mypopup.menu.OptionTitleObject;
import com.spirit.mypopup.menu.OptionValueInterface;
import com.spirit.mypopup.menu.adapter.MenuFliteAdapter;
import com.spirit.mypopup.menu.adapter.OnSelectItemListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main6Activity extends AppCompatActivity {
    private static final String TAG = "Main6Activity";
    private View decorView;
    private FrameLayout layout;
    private ViewGroup systemParent;
    private FilterMenuBar menu;
    private Map<OptionTitleInterface, OptionValueInterface> map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);

        map = new HashMap<>();

        List<CityBean> strings = new ArrayList<>();

        List<CityBean> chiled1 = new ArrayList<>();
        chiled1.add(new CityBean("市辖区", 11));

        List<CityBean> chiled2 = new ArrayList<>();
        chiled2.add(new CityBean("长沙", 22));
        chiled2.add(new CityBean("衡阳", 23));
        chiled2.add(new CityBean("常德", 24));

        List<CityBean> chiled3 = new ArrayList<>();
        chiled3.add(new CityBean("广州", 32));
        chiled3.add(new CityBean("石牌", 33));
        chiled3.add(new CityBean("常平", 34));

        strings.add(new CityBean("北京", 1, chiled1));
        strings.add(new CityBean("湖南", 2, chiled2));
        strings.add(new CityBean("广东", 3, chiled3));


        List<LikeBean> strings2 = new ArrayList<>();
        strings2.add(new LikeBean("吉他", 1));
        strings2.add(new LikeBean("钢琴", 1));
        strings2.add(new LikeBean("弟子", 1));
        strings2.add(new LikeBean("游戏", 1));
        strings2.add(new LikeBean("手机", 1));
        strings2.add(new LikeBean("爬山", 1));
        strings2.add(new LikeBean("游泳", 1));
        strings2.add(new LikeBean("吉他", 1));
        strings2.add(new LikeBean("钢琴", 1));
        strings2.add(new LikeBean("弟子", 1));
        strings2.add(new LikeBean("游戏", 1));
        strings2.add(new LikeBean("手机", 1));
        strings2.add(new LikeBean("爬山", 1));
        strings2.add(new LikeBean("游泳", 1));
        strings2.add(new LikeBean("吉他", 1));
        strings2.add(new LikeBean("钢琴", 1));
        strings2.add(new LikeBean("弟子", 1));
        strings2.add(new LikeBean("游戏", 1));
        strings2.add(new LikeBean("手机", 1));
        strings2.add(new LikeBean("爬山", 1));
        strings2.add(new LikeBean("游泳", 1));


        List<LikeBean> strings3 = new ArrayList<>();
        strings3.add(new LikeBean("12", 1));
        strings3.add(new LikeBean("23", 1));


        MenuFliteAdapter adapter1 = new MenuFliteAdapter(MenuType.DOUBLE_MENU, new OptionTitleObject("城市"), strings);
        MenuFliteAdapter adapter2 = new MenuFliteAdapter(MenuType.SIGIN_MENU, new OptionTitleObject("爱好"), strings2);
        MenuFliteAdapter adapter3 = new MenuFliteAdapter(MenuType.SIGIN_MENU, new OptionTitleObject("年龄"), strings3);


        map.put(new OptionTitleObject("城市"), new OptionValueObject(MenuType.DOUBLE_MENU, strings));
        map.put(new OptionTitleObject("爱好"), new OptionValueObject(MenuType.SIGIN_MENU, strings2));
        map.put(new OptionTitleObject("年龄"), new OptionValueObject(MenuType.SIGIN_MENU, strings3));

        menu = findViewById(R.id.menu);

        menu.post(new Runnable() {
            @Override
            public void run() {
                menu.setDatas(adapter1).setOnSelectItemListener(new OnSelectItemListener() {
                    @Override
                    public void onSelectItemListener(OptionObject optionObj) {
                        Log.i(TAG, "onSelectItemListener: " + optionObj.getTitle());
                    }
                });
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        return super.onTouchEvent(event);
    }

    public void add(View view) {
        systemParent.addView(layout);
    }

    public void remove(View view) {
        systemParent.removeView(layout);
    }
}
